# @Time  :2021/4/8 21:19
# @Author: Houtaroy
from flask import jsonify

from .support import NameEnum


class ResultCode(NameEnum):
    SUCCESS = (200, '成功')
    FORBIDDEN = (403, '禁止访问')
    ERROR = (500, '服务器内部错误')


class RestResult:
    @classmethod
    def custom(cls, code: int, message: str, data: object = None):
        return jsonify(code=code, message=message, data=data)

    @classmethod
    def success(cls, data: object = None, message: str = ResultCode.SUCCESS.label):
        return cls.custom(ResultCode.SUCCESS.value, message, data)

    @classmethod
    def forbidden(cls, message: str = ResultCode.FORBIDDEN.label, data: object = None):
        return cls.custom(ResultCode.FORBIDDEN.value, message, data)

    @classmethod
    def error(cls, message: str = ResultCode.ERROR.label, data: object = None):
        return cls.custom(ResultCode.ERROR.value, message, data)
